package com.jdbc;

import org.junit.Test;

import java.sql.*;

public class JdbcTest {
    public JdbcTest() throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.cj.jdbc.Driver");
        String url="jdbc:mysql://localhost:3306/db_test?useSSL=false&allowPublicKeyRetrieval=true";
        String username="root";
        String password="1234";
        int id=1;
        String sql="select * from tb_book where bookId="+id;
        Connection connection= DriverManager.getConnection(url,username,password);
        Statement statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery(sql);
//        ResultSetMetaData metaData = resultSet.getMetaData();
//        System.out.println(metaData);
        while (resultSet.next()){
            System.out.println(resultSet.getInt("bookId"));
            System.out.println(resultSet.getString("bookName"));
            System.out.println(resultSet.getDate("publishTime"));
        }
        connection.close();
        statement.close();
        resultSet.close();
    }

    @Test
    public void test1() throws SQLException, ClassNotFoundException {
        new JdbcTest();

    }
}
